﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CustomsSystem.BLL;
using CustomsSystem.Model;

namespace WEB.password
{
    public partial class ClientPasswordChange : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CustomsSystem.Model.Client myClient = new CustomsSystem.Model.Client();
            if (!Page.IsPostBack)
            {
                myClient.ClientName = Session["ClientName"].ToString();
                ClientName.Text = myClient.ClientName;
            }
        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            CustomsSystem.Model.password_change model = new CustomsSystem.Model.password_change();
            ChangeManage changeManage = new ChangeManage();
            model.ClientName = ClientName.Text.Trim();
            model.OldPassWord = stringpro .md5 (OldPassWord.Text.Trim());
            model.NewPassWord1 =stringpro .md5 ( NewPassWord1.Text.Trim());
            model.NewPassWord2 =stringpro .md5 ( NewPassWord2.Text.Trim());
            if (model.OldPassWord == "" & model.NewPassWord1 == "" & model.NewPassWord2 == "")
            {
                Response.Write("<script>alert('请输入密码')</script>");
            }
            else
            {
                if (changeManage.Judge(model) == true)
                {
                    if (model.NewPassWord1 == model.OldPassWord)
                    {
                        Response.Write("<script>alert('原密码和新密码一样，无需更改')</script>");
                    }
                    else
                    {
                        if (changeManage.ClientChange(model) == true)
                        {
                            Response.Write("<script>alert('更改密码成功')</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('原密码输入有误，请重新输入')</script>");
                        }
                    }
                }
                else
                {
                    Response.Write("<script>alert('两次输入的密码不一致，请重新输入')</script>");
                }
            }
        }
    }
}